Baby RSA [Crypto]

Crypto

We've intercepted this RSA encrypted message.

2193 1745 2164 970 1466 2495 1438
1412 1745 1745 2302 1163 2181 1613
1438 884 2495 2302 2164 2181 884
2302 1703 1924 2302 1801 1412 2495
53 1337 2217

we know it was encrypted with the following public key e: 569 n: 2533

Recon

We see that n is very small, so we can easily get q and p from it:

$ factor 2533
2533: 17 149

With that we could decrypt the message, where every number represents an ascii code and combined gave us the flag.

Code

msg = "2193 1745 2164 970 1466 2495 1438 1412 1745 1745 2302 1163 2181 1613 1438 884 2495 2302 2164 2181 884 2302 1703 1924 2302 1801 1412 2495 53 1337 2217".split(" ")
e = 569
n = 2533 # 17 * 149
p = 17
q = 149

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

d = modinv(e, (p-1)*(q-1))
out = ""
for m in msg:
    out += chr(pow(int(m), d, n))

print out

Flag

flag{sm4ll_pr1m3s_ar3_t0_e4sy}